﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Iservices;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace Hr.Controllers
{
    /// <summary>
    /// 薪酬标准单详细信息
    /// </summary>
    public class SataryTwoController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
        private readonly Isalary_standard_detailsServices d;
        public SataryTwoController(Isalary_standard_detailsServices d)
        {
            this.d = d;
        }
        [HttpGet]
        public IActionResult salary_item_register()
        {
            return View();
        }
       /// <summary>
       /// 添加数据
       /// </summary>
       /// <param name="s"></param>
       /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> salary_item_register(salary_standard_details s)
        {
            if (ModelState.IsValid)
            {
                int result = await d.Add(s);
                if (result > 0)
                {
                    return Content("<script>alert('添加成功');window.location.href='/SataryTwo/salary_item'</script>", "text/html", Encoding.Default);
                }
                else
                {
                    return View(s);
                }
            }
            else
            {
                return View(s);
            }

        }
        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> salary_item()
        {
            //获取数据，显示在页面
            List<salary_standard_details> dt = await d.Select();
            ViewData.Model = dt;
            return View();
        }
        public async Task<IActionResult> Del(int id)
        {
            int dt = await d.Del(id);
            if (dt > 0)
            {
               // return Content("<script>alert('删除成功');window.location.href='/Satary/public_char'</script>", "text/html", Encoding.Default);
                return Content("<script>alert('删除成功');window.location.href='/SataryTwo/salary_item'</script>","text/html",Encoding.Default);
            }
            else
            {
                return Content("<script>alert('删除失败');window.location.href='SataryTwo/salary_item'</script>");
            }
        }
    }
}
